package com.fyy.content.api;

import com.fyy.base.exception.ValidationGroups;
import com.fyy.base.model.PageParams;
import com.fyy.base.model.PageResult;
import com.fyy.content.model.dto.AddCourseDto;
import com.fyy.content.model.dto.CourseBaseInfoDTO;
import com.fyy.content.model.dto.QueryCourseParamsDTO;
import com.fyy.content.model.dto.UpdateCourseDTO;
import com.fyy.content.model.po.CourseBasePO;
import com.fyy.content.service.CourseBaseInfoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * @author fyy
 * @version 1.0
 * @description
 * @date 2024/7/7 16:46
 */
@Api(value = "课程信息编辑接口",tags = "课程信息编辑接口")
@RestController
public class CourseBaseInfoController {

    @Autowired
    private CourseBaseInfoService courseBaseInfoService;

    @ApiOperation("课程分页查询")
    @PostMapping("/course/list")
    public PageResult<CourseBasePO> list(PageParams pageParams, @RequestBody(required=false) QueryCourseParamsDTO queryCourseParams) {
        PageResult<CourseBasePO> basePOPageResult = courseBaseInfoService.queryCourseBaseList(pageParams, queryCourseParams);
        return basePOPageResult;
    }

    @ApiOperation("新增课程基础信息")
    @PostMapping("/course")
    public CourseBaseInfoDTO createCourseBase(@RequestBody @Validated(ValidationGroups.Insert.class) AddCourseDto addCourseDto) {
        Long companyId = 1232141425L;
        return courseBaseInfoService.createCourseBase(companyId, addCourseDto);
    }

    @ApiOperation("查询课程基础信息")
    @GetMapping("/course/{courseId}")
    public CourseBaseInfoDTO getCourseBase(@PathVariable Long courseId) {
        return courseBaseInfoService.getCourseBaseInfo(courseId);
    }

    @ApiOperation("修改课程基础信息")
    @PutMapping("/course")
    public CourseBaseInfoDTO updateCourse(@RequestBody @Validated UpdateCourseDTO updateCourseDTO) {
        Long companyId = 1232141425L;
        return courseBaseInfoService.updateCourseBaseInfo(companyId, updateCourseDTO);
    }

}
